﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Interfaces;
using Cofe.Core.Property;
using Cofe.Core.Service;

namespace Cofe.Media
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFEMEDIA)]
    public class MediaPropertyProviderFactory : ISecondaryPropertyProviderFactory
    {
        public IEnumerable<IPropertyProvider> GetSecoondaryPropertyProviders(IPropertyHost propertyHost)
        {
            if (!(propertyHost.SecondaryPropertyProviders.Any((p) => p is ImagePropertyProvider)))
            {
                string parseName = propertyHost.Behaviors.GetProperty<string>(CofeProperties.FullParseName);
                string ext = PathFE.GetExtension(parseName).ToLower();
                switch (ext)
                {
                    case ".jpg":
                    case ".jpeg":
                        yield return new ExifPropertyProvider(propertyHost);
                        break;
                    case ".bmp":
                    case ".gif":
                    case ".png":
                        yield return new ImagePropertyProvider(propertyHost);
                        break;
                }
                
                    
                
            }
                
        }

        public void OnImported(IServiceLocater serviceLocater)
        {

        }

        private IServiceLocater _serviceLocater = null;

        public IServiceLocater ServiceLocater
        {
            get { return _serviceLocater ?? CofeServices.ServiceLocater; }
            set { _serviceLocater = value; }
        }

    }
    
}
